﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hangfire;
using Abp.BackgroundJobs;
using Abp.Dependency;
using Abp.ObjectMapping;
using System.ComponentModel;
using Abp.Domain.Repositories;
using Castle.Core.Logging;

namespace AVIS.OutBound.WizardAgent
{
    [Queue("wizardlog")]
    public class AddWizardMonitorLogJob : BackgroundJob<AddWizardMonitorLogJobArgs>, ITransientDependency
    {
        #region 构造函数
        public ILogger Logger { get; set; }

        private readonly IObjectMapper _objectMapper;
        private readonly IRepository<AddWizardMonitorLogJobArgs> _logRepository;

        public AddWizardMonitorLogJob(IObjectMapper objectMapper,
            IRepository<AddWizardMonitorLogJobArgs> logRepository)
        {
            _objectMapper = objectMapper;
            _logRepository = logRepository;
            Logger = NullLogger.Instance;
        }
        #endregion  

        [DisplayName("Wizard监控日志（{0}）")]
        [Description("插入Wizard接口调用的监控日志")]
        [Queue("wizardlog")]
        public override void Execute(AddWizardMonitorLogJobArgs args)
        {
            try
            {
                // 插入数据库
                _logRepository.Insert(args);
            }
            catch (Exception ex)
            {
                Logger.Error("AddWizardMonitorLogJob报错", ex);
            }
        }
    }
}
